<!-- 机械课运维-危废管理-危险废弃物出入库台账 -->
<template>
  <div class="app-container">
    <px-form v-show="showSearch" ref="queryRef" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
      <px-form-item label="废物名称">
        <px-select v-model="queryParams.dictWasteCode" placeholder="请选择废物名称" filterable clearable style="width: 240px">
          <px-option v-for="dict in liquidList" :key="dict.id" :label="dict.itemName" :value="dict.itemValue" />
        </px-select>
      </px-form-item>
      <px-form-item label="入库时间" style="width: 516px !important">
        <px-date-picker
          v-model="dateRange"
          type="datetimerange"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
          format="YYYY-MM-DD HH:mm:ss"
          value-format="YYYY-MM-DD HH:mm:ss"
          :default-time="defaultTime"
        />
      </px-form-item>
      <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery('search')">搜索</px-button>
      <px-button style="margin-top: -17px" icon="" @click="resetQuery">重置</px-button>
    </px-form>

    <px-row :gutter="10" class="mb8">
      <!-- <px-col :span="1.5">
        <px-button v-has="'CommonEquipListAdd'" type="primary" icon="" @click="handleAdd">新增</px-button>
      </px-col> -->
      <px-col :span="1.5">
        <px-button type="primary" plain icon="" @click="handleExport">批量下载</px-button>
      </px-col>

      <!-- <px-col :span="1.5">
        <px-button v-has="'CommonEquipListDelete'" type="danger" plain icon="" :disabled="multiple" @click="handleDelete">删除</px-button>
      </px-col> -->
    </px-row>

    <px-table
      v-if="!equipopen && !equipopenDetail"
      v-loading="loading"
      :data="typeList"
      height="calc(100vh - 329px)"
      show-overflow-tooltip
      border
      @selection-change="handleSelectionChange"
    >
      <!-- <px-table-column type="selection" width="40" /> -->
      <px-table-column label="序号" align="center" prop="id" />
      <px-table-column label="废物名称" prop="wasteName">
        <template #default="scope">
          <span>{{ scope.row.wasteName }}</span>
        </template>
      </px-table-column>

      <px-table-column label="危废特性" prop="hazardCharacteristics">
        <template #default="scope">
          <span>{{ scope.row.hazardCharacteristics }}</span>
        </template>
      </px-table-column>
      <px-table-column label="入库日期" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.inboundTime }}</span>
        </template>
      </px-table-column>
      <!-- <px-table-column label="入库时间" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.inboundTime }}</span>
        </template>
      </px-table-column> -->
      <px-table-column label="废物数量" prop="inboundQuantity">
        <template #default="scope">
          <span>{{ scope.row.inboundQuantity }}{{ scope.row.wasteUnit }}</span>
        </template>
      </px-table-column>
      <px-table-column label="盛废容器及容积" width="120" prop="container">
        <template #default="scope">
          <span>{{ scope.row.container }}</span>
        </template>
      </px-table-column>
      <px-table-column label="容器存放位置" width="110" prop="storageLocation">
        <template #default="scope">
          <span>{{ scope.row.storageLocation }}</span>
        </template>
      </px-table-column>
      <px-table-column label="运送部门" prop="transportDepartment">
        <template #default="scope">
          <span>{{ scope.row.transportDepartment }}</span>
        </template>
      </px-table-column>
      <px-table-column label="接收人" prop="receiverName">
        <template #default="scope">
          <span>{{ scope.row.receiverName }}</span>
        </template>
      </px-table-column>
      <px-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <div v-if="scope.row.status == 'VALID'" class="level1">有效</div>
          <div v-else class="level2">无效</div>
        </template>
      </px-table-column>
      <px-table-column label="出库日期" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.outboundTime }}</span>
        </template>
      </px-table-column>
      <px-table-column label="废物去向" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.wasteCompany }}</span>
        </template>
      </px-table-column>
      <px-table-column label="暂存部门" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.temporaryStorageDepartment }}</span>
        </template>
      </px-table-column>
      <px-table-column label="接收单位" prop="inboundTime">
        <template #default="scope">
          <span>{{ scope.row.receiveCompany }}</span>
        </template>
      </px-table-column>
      <template #empty>
        <px-empty :image-size="150" />
      </template>
    </px-table>

    <pagination
      v-if="!equipopen && !equipopenDetail"
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      style="margin-bottom: -10px"
      :total="total"
      @pagination="getList"
    />
  </div>
</template>

<script setup lang="ts">
import { useRoute } from "vue-router";
import { getCurrentInstance, ref, toRefs, reactive } from "vue";
import { getToken } from "@/utils/auth";
import { queryChildByTypeCodeAndItemValue } from "@/api/waterClass";
import { wflqueryListPage } from "@/api/hazardousWasteS";
const defaultTime: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 1), new Date(2000, 1, 1, 23, 59, 59)];

const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}
const { proxy }: any = getCurrentInstance();

const typeList = ref([]);
const equipopen = ref(false);
const equipopenDetail = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const total = ref(0);
const dateRange = ref([]);

// 图片是否上传完，是否可以保存
const savePhotoStatus = val => {
  photoStatusFlag.value = val;
};
// 文件是否上传完，是否可以保存
const saveFileStatus = val => {
  fileStatusFlag.value = val;
};
const data = reactive({
  liquidList: [],
  transportCompanyList: [],
  receiveCompanyList: [],
  typeIdList: [],
  categoryList: [],
  equipmentTypeList: [],
  positionList: [],
  equipmentDeptList: [],
  modelIdList: [],
  form: {},
  photoStatusFlag: false,
  fileStatusFlag: false,
  equipdata: {
    ledgerCode: "",
    wasteName: "",
    outFactoryTime: "",
    quantity: "",
    transportCompanyCode: "",
    transportCompanyName: "",
    carNumber: "",
    receiveCompanyCode: "",
    receiveCompanyName: "",
    outFactoryClassOperatorId: "",
    outFactoryClassOperatorName: "",
    outFactoryExternalOperatorName: "",
    driverName: "",
    description: "",
    updateTime: "",
    photo: [],
    attachment: []
  },
  queryParams: {
    orderByColumn: "",
    isAsc: "",
    dictWasteCode: "",
    startTime: "",
    endTime: "",
    status: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  headers: {
    Authorization: "Bearer " + getToken().accessToken || ""
  },
  moduleName: "",
  dialogImageUrl: "",
  imageVisible: false
});

const { liquidList, queryParams, form, photoStatusFlag, fileStatusFlag } = toRefs(data);
const getqueryCategoryList = () => {
  //固废代码
  queryChildByTypeCodeAndItemValue({
    value: "DS01",
    typeCode: "WTTS"
  }).then((response: any) => {
    console.log(response);
    liquidList.value = response;
  });
};
getqueryCategoryList();
function getList() {
  loading.value = true;
  if (dateRange.value != null) {
    queryParams.value.startTime = dateRange.value[0];
    queryParams.value.endTime = dateRange.value[1];
  } else {
    queryParams.value.startTime = "";
    queryParams.value.endTime = "";
  }

  wflqueryListPage(queryParams.value).then((response: any) => {
    typeList.value = response.data;
    total.value = response.total;
    loading.value = false;
  });
}

/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    dictionaryName: undefined,
    dictionaryType: undefined,
    status: "VALID",
    remarks: undefined
  };
  proxy.resetForm("dictRef");
}
/** 搜索按钮操作 */
function handleQuery(type) {
  if (type == "search") {
    queryParams.value.pageNum = 1;
  }
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    pageNum: queryParams.value.pageNum,
    pageSize: queryParams.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    dictWasteCode: "",
    startTime: "",
    endTime: "",
    status: "",
    orderBy: ""
  };
  dateRange.value = [];
  handleQuery("reset");
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download("post", "/operation/api/v1/water/hazardWasteOutDetail/solid/export", queryParams.value, "危险固废委外台账.xlsx");
}

getList();
</script>
<style scoped lang="scss">
.addEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.editorEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.px-dialog-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2002;
  width: 100%;
  height: 50px;
  padding-top: 10px;
  padding-right: 34px;
  text-align: right;
  background: white;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 16%);
}

.card-header {
  min-height: 40px;
  padding: 14px 15px 7px !important;
  cursor: pointer;
  user-select: none;
  background: #e7eefb;
}

.card-title {
  float: left;
  line-height: 14px;
}

.card-main {
  float: left;
  margin: -3px 8px 0 5px;
  cursor: pointer;
}

.box-card1 {
  width: calc(100% - 48px);
  height: 505px;
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card2 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card3 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card4 {
  width: calc(100% - 48px);
  height: 261px;
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.demo-form-inline {
  .px-input {
    --px-input-width: calc(100% - 100px);
  }

  .px-form-item {
    width: 100%;
  }

  .px-textarea__inner {
    width: calc(100% - 100px) !important;
  }

  .px-form-item__label {
    font-weight: 400 !important;
  }
}

.form-div {
  padding: 24px;

  .px-row {
    margin-bottom: 16px;
  }
}

.px-icon {
  font-size: 16px !important;
}

:deep(.px-tabs--top .px-tabs__item.is-top.is-active) {
  border: none;

  .pane-bottom {
    line-height: 30px;
    border-bottom: 2px solid #3b82f6;
  }
}

:deep(.px-tabs .px-tabs__item) {
  .pane-bottom {
    line-height: 30px;
  }
}

.pane-line {
  position: absolute;
  top: 12px;
  right: 0;
  height: 15px;
  color: #dcdcdc;
  border-left: 1px solid #dcdcdc;
}

:deep(.custom-form-ui .px-form-item) {
  width: 250px !important;
}

:deep(.px-upload) {
  --px-upload-dragger-padding-horizontal: 18px;
}

.file-upload-dom {
  :deep(.px-upload-list--picture-card .px-upload-list__item) {
    position: relative;
    width: 96px;
    height: 96px;
    overflow: visible;

    .filebg {
      position: absolute;
      display: none;
      width: 96px;
      height: 96px;
      background: #0006;
    }

    .filedelect {
      margin: 35px;
      font-size: 22px !important;
      color: white;
      cursor: pointer;
    }

    &:hover {
      .filebg {
        display: block;
      }
    }

    .filesvg {
      position: absolute;
      top: 30px;
      left: 30px;
      font-size: 70px;
    }
  }
}

:deep(.px-upload-list--picture-card .px-upload-list__item) {
  width: 96px;
  height: 96px;
}

.filename {
  position: absolute;
  bottom: -30px;
  width: 96px;
  overflow: hidden;
  color: rgb(166 167 172);
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.px-descriptions__label.px-descriptions__cell.is-bordered-label) {
  width: 166px;
  background: #e7eefb;
  border: 1px solid #dfdfdf;
}

:deep(.px-descriptions__body .px-descriptions__table.is-bordered .px-descriptions__cell) {
  border: 1px solid #dfdfdf;
}

.cell-item {
  text-align: right;
}

:deep(.px-table__header) {
  thead {
    tr {
      background-color: #e7eefb !important;

      th {
        font-size: 13px;
        font-weight: bold;
        color: #000;
        background-color: #e7eefb !important;
      }
    }
  }
}

:deep(.px-table--isfixedHeader .px-table__header-wrapper .px-table-fixed-column--right) {
  background-color: #e7eefb !important;
}

:deep(.px-upload--picture-card) {
  --px-upload-picture-card-size: 93px;

  position: absolute;
}

:deep(.px-upload-list--picture-card > li:first-of-type) {
  margin-left: 104px;
}

:deep(.px-upload-list--picture-card) {
  min-height: 100px;
}

.level1 {
  width: 52px;
  height: 24px;
  margin: 0 auto;
  text-align: center;
  background: #ecfdf5;
  border: 1px solid #10b981;
  border-radius: 4px;
}

.level2 {
  width: 52px;
  height: 24px;
  margin: 0 auto;
  text-align: center;
  background: #fcf6ec;
  border: 1px solid #fda620;
  border-radius: 4px;
}

.level3 {
  width: 52px;
  height: 24px;
  margin: 0 auto;
  text-align: center;
  background: #eff6ff;
  border: 1px solid #3b82f6;
  border-radius: 4px;
}
</style>
